home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-04-04 | 4.1 KB | 153 lines | [TEXT/ALFA] |
- \ Section: Monitor and Extension Traps
-
- 6 constant dx \ horizontal differential
- 0B constant dy \ vertical differential
-
- variable theText 77C allot \ 1840 characters = 23 x 80 plus extra
- \ blank line for scrolling
-
- : $DB \ trap CH word, set horizontal position
- rY @ dx * 2+ @xy swap drop gotoxy
- ;
-
- : $DF \ trap CV word, set vertical position
- @xy drop rY @ dy * 4+ gotoxy
- ;
-
- : clrText ( -- ) \ clear the text buffer
- 780 theText + theText do 20 i c! loop ;
-
- : killText ( -- ) \ remove the top line in theText
- 780 theText + theText 50 + do
- i c@ i 50 - c! \ move all text up one line
- loop ;
-
- : $E7 \ trap $C300 - clear the screen
- cls clrText ;
-
- : >text ( x y c -- ) \ put c in the text buffer
- >r 4- dy / 1- swap 2- dx / 1- swap 50 * + r> swap theText + c! ;
-
- : <del \ handle a backspace or delete character (Mops)
- space space \ clear underscore
- @xy swap 12 - swap gotoxy \ turn off cursor, back pen up
- space @xy swap dx - swap 20 >text \ erase existing character if any
- @xy swap 6 - swap gotoxy \ back up again
- ;
-
- : ?scroll ( -- ) \ if the screen will scroll, kill top line in theText
- @xy swap drop 101 = if killText then ;
-
- : $F3 \ cout - output character in rA
- @xy drop 1E8 = if ?scroll cr then \ cr if 80 characters out on this line
- rA @ 7F and \ QForth sets hi bit, clear it
- dup 7F = if drop <del else \ delete
- dup 08 = if drop <del else \ backspace
- dup 0d = if drop space ?scroll cr else \ return
- dup 1F > if @xy rot dup emit >text else drop \ alphanumeric
- then then then then ;
-
- : >hex ( h -- ) \ print a single hex digit
- dup 9 > if 37 + rA ! $F3 else 30 + rA ! $F3 then ;
-
- : $C7 \ hex - output character in rA as two hex digits
- @xy drop 1E8 = if ?scroll cr then
- rA @ dup 10 / swap 10 mod swap >hex >hex ;
-
- : $CB \ put a random number in FF8E and FF8F
- 100 random FF8F $! 100 random FF8E $! ;
-
- : $BF \ put a random number on the stack from 0 to n-1
- popQF random pushQF ;
-
- : $BB { \ a b c -- } \ */ trap for scaled integer arithmetic
- popQF popQF popQF * swap / pushQF ;
-
- : $F7 \ output a cr
- space ?scroll cr ;
-
- : $FB \ get a key to rA
- 5F emit @xy swap 6 - swap gotoxy \ 5F = '_'
- -1 -> ?waiting ;
-
- : $A7 \ KEY? trap, push true if a key pressed
- ?terminal if FFFF pushQF else 0 pushQF then ;
-
- : depthQF \ depth of QForth stack
- F4 $@ ;
-
- variable xGR
- variable yGR
- : putPen \ restore graphics pen position
- xGR @ yGR @ gotoxy ;
-
- : savePen \ store graphics pen position
- @xy yGR ! xGR ! ;
-
- : $EB \ LineTo
- depthQF 1 > if \ at least two values
- @xy putPen \ save current position and move to old graphics position
- popQF popQF swap lineto \ move
- savePen gotoxy \ store new graphics position
- then
- ;
-
- : $EF \ MoveTo
- depthQF 1 > if
- @xy putPen
- popQF popQF swap gotoxy
- savePen gotoxy
- then
- ;
-
- : red 0CD call ForeColor ; \ Old-style colors
- : black 21 call ForeColor ;
- : yellow 45 call ForeColor ;
- : green 155 call ForeColor ;
- : blue 199 call ForeColor ;
- : white 1E call ForeColor ;
- : cyan 111 call ForeColor ;
- : magenta 89 call ForeColor ;
-
- : $E3 \ set drawing color
- depthQF 0 > if
- popQF
- dup 0 = if drop black else
- dup 1 = if drop red else
- dup 2 = if drop green else
- dup 3 = if drop blue else
- dup 4 = if drop cyan else
- dup 5 = if drop magenta else
- dup 6 = if drop yellow else
- 7 = if drop white else
- black then then then then then then
- then then then
- ;
-
- : $D7 \ plot a point, faster than using QForth code
- depthQF 1 > if
- @xy popQF dup yGR ! popQF dup xGR ! swap
- 2dup gotoxy lineto
- gotoxy
- then
- ;
-
- Mouse Mickey \ a mouse object
-
- : $D3 \ get mouse position and button status
- get: Mickey \ return button status and mouse position, x y b --
- rot pushQF \ push rX on QForth stack
- swap pushQF \ push rY on QForth stack
- 0= if 0 pushQF else FFFF pushQF then \ push button status on stack
- ;
-
- : $B3 \ 'type' trap
- popQF popQF dup rot + swap do i $@ rA ! $F3 loop ;
-
- : $AF \ 'room' trap
- 09DFF 0E6 $@ 0E7 $@ 100 * + - pushQF ;
-
- : $AB \ 'here' trap
- 0E6 $@ 0E7 $@ 100 * + 10 + pushQF ;
-
-